﻿using System;
using VsxTools.Attributes;

namespace VsxTools.OutputWindow
{
    public abstract class OutputPaneDefinition
    {
        private readonly string _name = "<Name not defined>";
        private readonly bool _initiallyVisible = true;
        private readonly bool _clearWithSolution = false;
        private readonly bool _threadSafe = true;

        protected OutputPaneDefinition()
        {
            foreach (var attr in GetType().GetCustomAttributes(false))
            {
                var panelNameAttribute = attr as PanelNameAttribute;
                if (panelNameAttribute != null)
                {
                    _name = panelNameAttribute.Value;
                    continue;
                }
                var initiallyVisibleAttribute = attr as InitiallyVisibleAttribute;
                if (initiallyVisibleAttribute != null)
                {
                    _initiallyVisible = initiallyVisibleAttribute.Value;
                    continue;
                }
                var clearWithSolutionAttribute = attr as ClearWithSolutionAttribute;
                if (clearWithSolutionAttribute != null)
                {
                    _clearWithSolution = clearWithSolutionAttribute.Value;
                    continue;
                }
                var threadSafeAttribute = attr as ThreadSafeAttribute;
                if (threadSafeAttribute != null)
                {
                    _threadSafe = threadSafeAttribute.Value;
                }
            }
        }

        public virtual Guid Guid
        {
            get { return GetType().GUID; }
        }

        public string Name
        {
            get { return _name; }
        }

        public bool InitiallyVisible
        {
            get { return _initiallyVisible; }
        }

        public bool ClearWithSolution
        {
            get { return _clearWithSolution; }
        }

        public bool ThreadSafe
        {
            get { return _threadSafe; }
        }
        public bool IsSilent { get; internal set; }
    }
}
